package ts.group.webapp.market.controller.login;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import ts.group.webapp.market.common.core.util.ResponseData;
import ts.group.webapp.market.common.core.web.controller.BaseController;
import ts.group.webapp.market.model.TUser;
import ts.group.webapp.market.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
	
	@Autowired
	private IUserService userService; 
	
	@RequestMapping("/login") 
	@ResponseBody
	public ResponseData login(HttpServletRequest request, HttpServletResponse response,HttpSession session) {
		TUser user = new TUser();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		return userService.getLoginModel(request,  response,  session, user,  username ,  password);
		
	}
	
	@RequestMapping("/logout") 
	public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
		request.getSession().invalidate();
		response.sendRedirect(request.getContextPath() + "/welcome");   
	}
	
}